package cn.niit.smbms.config;

import cn.niit.smbms.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

@Configuration
public class WebMVCConfig implements WebMvcConfigurer {
    @Value("${springmvc.interceptor.exclude-path-patterns}")
    private List<String> EXCLUDE_PATH_PATTERNS;

    /**
     * 注册拦截器
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        System.out.println("EXCLUDE_PATH_PATTERNS：" + EXCLUDE_PATH_PATTERNS);
        InterceptorRegistration registration = registry.addInterceptor((new LoginInterceptor()));
        registration.addPathPatterns("/**");  //拦截所有请求

        //registration.excludePathPatterns("/css/**","/login","calendar/**","/images/**","/js/**");//设置拦截器白名单
        registration.excludePathPatterns(EXCLUDE_PATH_PATTERNS);//设置拦截器白名单（自定义配置的）
    }
}
